import * as XLSX from "xlsx";
// import * as FileSaver from "file-saver";

export function exportDataToExcel(tableData: any[]): void {
  // 将 tableData 转换成 worksheet
  const ws = XLSX.utils.json_to_sheet(tableData);
ws.cl
  // 创建一个新的 workbook
  const wb = XLSX.utils.book_new();

  // 添加 worksheet 到 workbook
  XLSX.utils.book_append_sheet(wb, ws, "Sheet1");

  // 将 workbook 写入 Excel 文件
  const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "array" });

  // 创建 Blob 对象
  const blob = new Blob([excelBuffer], { type: "application/octet-stream" });

  // 创建下载链接
  const url = window.URL.createObjectURL(blob);

  // 创建隐藏的可下载链接
  const a = document.createElement("a");
  a.href = url;
  a.download = "exported_data.xlsx";
  a.click();

  // 清除 URL
  window.URL.revokeObjectURL(url);
}



